package xpn.platform.modules.todo.todolink;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.rest.webmvc.RepositoryRestController;
import org.springframework.web.bind.annotation.*;
import xpn.platform.common.repository.XpnRepositoryController;
import xpn.platform.common.util.Tool;
import xpn.platform.modules.todo.common.BatchCreateRequestDTO;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * 待办  Controller
 *
 * @author zyk
 */
@RepositoryRestController
@ResponseBody
@RequestMapping("/todo_link")
public class TodoLinkController extends XpnRepositoryController<TodoLink, Long> {

	@Autowired
	private HttpServletRequest request = null;
    @Autowired
    TodoService service;

    /**
     * 批量创建
     *
     * @param request
     */
    @PostMapping("batch_create")
    public void batchCreate(@Valid @RequestBody BatchCreateRequestDTO request) {
        service.batchCreate(request);
    }

    /**
     * 批量移入已办
     *
     * @paramr request
     */
    @PostMapping("to_done")
    public void batchToDone(@Valid @RequestBody String[] ids) {
        service.batchToDone(ids);
    }

    /**
     * 根据业务Id  待办移入已办
     *
     * @param taskId
     */
    @PostMapping("to_done/{taskId}")
    public void toDone(@PathVariable("taskId") String taskId) {
        service.toDone(taskId);
    }

    /**
     * 根据业务Id删除 待办
     *
     * @paramr request
     */
    @DeleteMapping("task/{taskId}")
    public void deleteByTask(@PathVariable("taskId") String taskId) {
        service.deleteByTaskId(taskId);
    }
    /**
     * 批量移移交待办
     *
     * @paramr request
     */
    @PostMapping("changeto_done")
    public void changeToDone(@Valid @RequestBody String[] ids) {
    	if (!Tool.isEmpty(this.request.getParameter("userId"))) {
    		service.changeToDone(ids,this.request.getParameter("userId"));

		}else{
			service.changeToDone(ids,null);
		}



    }

    /**
     * 查询待办数量
     *
     * @paramr request
     */
    @GetMapping("getTodoCount/{userId}")
    public Long getTodoCount(@PathVariable("userId") String userId) {
        return service.getTodoCount(userId);
    }

}
